package com.lvmama.pangolin.timer.processor;



import java.sql.Timestamp;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;

import com.lvmama.pangolin.busi.timer.TimerManager;
import com.lvmama.pangolin.busi.timer.TimerManagerAssist;
import com.lvmama.pangolin.service.TimerService;
import com.lvmama.pangolin.timer.CommonJob;
import com.lvmama.pangolin.util.SpringContextUtil;


public class PythonActor extends CommonJob {

	@Autowired
	private TimerService timerService;
	
	private Logger logger = Logger.getLogger(PythonActor.class);
	@Override
	public void runJob(JobExecutionContext context, String parameter)
	{
		try
		{
			
			String timer_id  = (String)context.getJobDetail().getJobDataMap()
					.get(TimerManager.TIMER_ID);
			String timerCode  = (String)context.getJobDetail().getJobDataMap()
					.get(TimerManager.TIMER_CODE);
			logger.info("timer_id: " + timer_id);
			if(timerService == null)
			{
				timerService = (TimerService) SpringContextUtil.getBean(TimerService.class);
			}
			Map<String,Object> param = new HashMap<String,Object>();
			param.put("timer_id", timer_id);
			param.put("timer_status", "1");
			param.put("timer_type", "PYTHON");
			param.put("oper_time", new Timestamp(new Date().getTime()));
			timerService.updateTimerByCon(param);
			new TimerManagerAssist().removeJob(timerCode);
			
		}catch (Exception e)
		{
			logger.error("更新任务状态失败!",e);
		}
		
		
		
	}

}
